//
//  ClientSocket.h
//  CocoaAsyncSocketClient
//
//  Created by lixiaoyi on 2018/6/7.
//  Copyright © 2018年 lixiaoyi. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "GCDAsyncSocket.h"

#define HEART_TIME 5

NS_ASSUME_NONNULL_BEGIN

@protocol ClientSocketDelegate
@optional
- (void)clientSocket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port;
- (void)clientSocket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag;

- (void)clientSocketDidDisconnect:(GCDAsyncSocket *)sock
                        withError:(nullable NSError *)err;

@end

@interface ClientSocket : GCDAsyncSocket<GCDAsyncSocketDelegate,ClientSocketDelegate>
@property (nonatomic,strong) GCDAsyncSocket *socket;
@property (nonatomic,assign) id<ClientSocketDelegate> socketDelegate;

// 主机IP
@property (nonatomic,copy) NSString *socketHost;

// 端口号
@property (nonatomic) uint16_t socketPort;

// 是否连接
@property (nonatomic) BOOL connectd;

// 心跳timer
@property (strong, nonatomic) NSTimer *connectTimer;

// 记录发送心跳的时间
@property (strong, nonatomic) NSDate *sendHeartDt;

// 记录心跳接收时间
@property (strong, nonatomic) NSDate *receHearDt;

+ (ClientSocket *)shareSocket;

- (void)autoConnection;

- (void)addTimer;

- (void)doAck:(int32_t)messId;

- (void)disConn;
+ (void)attempDealloc;

NS_ASSUME_NONNULL_END

@end
